package com.garen.sys.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.*;

import com.alibaba.fastjson.annotation.JSONField;
import com.garen.common.IEasyUITree;
import com.garen.orm.annotation.Formula;


@Table(name="fire_org")
public class FireOrg implements IEasyUITree{
	
	public final static int ORG_TYPE_LOCHUS = 4;
	
	private List<IEasyUITree> children = new ArrayList<>();
	
	@JSONField(serialize=false)
	private boolean flag;
	/*
	 * 父级部门名称
	 * */
	@Formula(name="org_parent_name",value="select org_short_name "
			+ " from fire_org tt where tt.org_id = t.org_parent_id ")
	private String orgParentName;
	
	/*
	 * 中队长
	 * */
	@Formula(name="leader_name1",value="select user_name "
			+ " from fire_user tt where tt.user_org_id = t.org_id and tt.user_post = '4' ")
	private String leaderName1;
	
	/*
	 * 指挥员
	 * */
	@Formula(name="leader_name2",value="select user_name "
			+ " from fire_user tt where tt.user_org_id = t.org_id and tt.user_post = '5' ")
	private String leaderName2;
	
	/*
	 * 编制人数
	 * */
	@Formula(name="org_user_count",value="select count(1) "
			+ " from fire_user tt where tt.user_org_id = t.org_id")
	private Integer orgUserCount;
	
	/*
	 * 值班人数
	 * */
	@Formula(name="user_duty_count",value="select count(1) "
			+ " from fire_duty tt where tt.fire_org = t.org_id")
	private Integer userDutyCount;
	
	/*
	 * 编制车辆
	 * */
	@Formula(name="org_car_count",value="select count(1) "
			+ " from fire_car tt where tt.car_org_id = t.org_id")
	private Integer orgCarCount;
	

	/*
	 * 值班车辆
	 * */
	@Formula(name="car_duty_count",value="select count(distinct fire_car) "
			+ " from fire_duty tt where tt.fire_org = t.org_id")
	private Integer carDutyCount;
	
	/**
	*机构类型: 1总队2支队3大队4中队
	*/
	@Column(name = "org_type",nullable=false)
	private Integer orgType;

	/**
	*编制人数
	*/
	@Column(name = "org_count")
	private Integer orgCount;

	/**
	*部门代码
	*/
	@Column(name = "org_code")
	private String orgCode;

	/**
	*部门UUID
	*/
	@Column(name = "org_uuid")
	private String orgUUID;
	
	/**
	*经度
	*/
	@Column(name = "org_lng")
	private String orgLng;

	/**
	*机构全称
	*/
	@Column(name = "org_all_name",nullable=false)
	private String orgAllName;

	/**
	*纬度
	*/
	@Column(name = "org_lat")
	private String orgLat;

	/**
	*机构简称
	*/
	@Column(name = "org_short_name")
	private String orgShortName;

	/**
	*联系电话
	*/
	@Column(name = "org_phone")
	private String orgPhone;
	
	/**
	*机构ID
	*/
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "org_id",nullable=false)
	private Integer orgId;

	/**
	*父ID
	*/
	@Column(name = "org_parent_id",nullable=false)
	private Integer orgParentId;

	/*
	 * 部门类型名称
	 * */
	public String getOrgTypeName() {
		int type = (orgType == null || orgType > 4)?0:orgType;
		String []strs = {"","总队","支队","大队","中队"};
		return strs[type];
	}
	

	public Integer getOrgType() {
		return orgType;
	}

	public void setOrgType(Integer orgType) {
		this.orgType=orgType;
	}

	public Integer getOrgCount() {
		return orgCount;
	}

	public void setOrgCount(Integer orgCount) {
		this.orgCount=orgCount;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode=orgCode;
	}

	public String getOrgLng() {
		return orgLng;
	}

	public void setOrgLng(String orgLng) {
		this.orgLng=orgLng;
	}

	public String getOrgAllName() {
		return orgAllName;
	}

	public void setOrgAllName(String orgAllName) {
		this.orgAllName=orgAllName;
	}

	public String getOrgLat() {
		return orgLat;
	}

	public void setOrgLat(String orgLat) {
		this.orgLat=orgLat;
	}

	public String getOrgShortName() {
		return orgShortName;
	}

	public void setOrgShortName(String orgShortName) {
		this.orgShortName=orgShortName;
	}

	public Integer getOrgId() {
		return orgId;
	}

	public void setOrgId(Integer orgId) {
		this.orgId=orgId;
	}

	public Integer getOrgParentId() {
		return orgParentId;
	}

	public void setOrgParentId(Integer orgParentId) {
		this.orgParentId=orgParentId;
	}


	public String getOrgParentName() {
		return orgParentName;
	}


	public void setOrgParentName(String orgParentName) {
		this.orgParentName = orgParentName;
	}


	public String getLeaderName1() {
		return leaderName1;
	}


	public void setLeaderName1(String leaderName1) {
		this.leaderName1 = leaderName1;
	}


	public String getLeaderName2() {
		return leaderName2;
	}


	public void setLeaderName2(String leaderName2) {
		this.leaderName2 = leaderName2;
	}


	public Integer getOrgUserCount() {
		return orgUserCount;
	}


	public void setOrgUserCount(Integer orgUserCount) {
		this.orgUserCount = orgUserCount;
	}


	public Integer getOrgCarCount() {
		return orgCarCount;
	}


	public void setOrgCarCount(Integer orgCarCount) {
		this.orgCarCount = orgCarCount;
	}


	public Integer getUserDutyCount() {
		return userDutyCount;
	}


	public void setUserDutyCount(Integer userDutyCount) {
		this.userDutyCount = userDutyCount;
	}


	public Integer getCarDutyCount() {
		return carDutyCount;
	}


	public void setCarDutyCount(Integer carDutyCount) {
		this.carDutyCount = carDutyCount;
	}


	@Override
	public Integer getId() {
		return orgId;
	}


	@Override
	public Integer getPid() {
		return orgParentId;
	}


	@Override
	public String getText() {
		return orgShortName;
	}


	@Override
	public void setChecked(boolean check) {
		
	}


	@Override
	public List<IEasyUITree> getChildren() {
		return children;
	}


	@Override
	public void setState(String state) {
	}


	@Override
	public void setFlag(boolean flag) {
		this.flag = flag;
	}


	@Override
	public boolean getFlag() {
		return flag;
	}


	public String getOrgUUID() {
		return orgUUID;
	}


	public void setOrgUUID(String orgUUID) {
		this.orgUUID = orgUUID;
	}


	public String getOrgPhone() {
		return orgPhone;
	}


	public void setOrgPhone(String orgPhone) {
		this.orgPhone = orgPhone;
	}

}
